package gfo

import grails.test.*

class TournamentIntTests extends GroovyTestCase {
    protected void setUp() {
        //PLAYERS--------------------------------------------------
        new Player(fullName: "Wilson Edens").save()
        new Player(fullName: "Adam Krosnick").save()
        new Player(fullName: "Daniel Shaver").save()
        new Player(fullName: "Ben Hoagland").save()
        new Player(fullName: "Tommy Stephens").save()
        new Player(fullName: "Rowan Jones").save()
        new Player(fullName: "Houston Jones").save()
        new Player(fullName: "Zach Tidmore").save()

        //FIGHTERS------------------------------------------------------
        new Fighter(name: 'Mario').save()
        new Fighter(name: 'Luigi').save()
        new Fighter(name: 'Peach').save()
        new Fighter(name: 'Bowser').save()
        new Fighter(name: 'Donkey Kong').save()
        new Fighter(name: 'Diddy Kong').save()
        new Fighter(name: 'Yoshi').save()
        new Fighter(name: 'Wario').save()
        new Fighter(name:  'Link').save()
        new Fighter(name: 'Zelda').save()//think about this one
        new Fighter(name: 'Ganondorf').save()
        new Fighter(name: 'Toon Link').save()
        new Fighter(name: 'Samus').save()
        new Fighter(name: 'Zero Suit Samus').save()
        new Fighter(name: 'Pit').save()
        new Fighter(name:  'Ice Climbers').save()
        new Fighter(name: 'R.O.B.').save()
        new Fighter(name: 'Kirby').save()
        new Fighter(name: 'Meta Knight').save()
        new Fighter(name: 'King Dedede').save()
        new Fighter(name: 'Olimar').save()
        new Fighter(name: 'Fox').save()
        new Fighter(name: 'Falco').save()
        new Fighter(name: 'Wolf').save()
        new Fighter(name: 'Captain Falcon').save()
        new Fighter(name: 'Pikachu').save()
        new Fighter(name: 'Pokemon Trainer').save()
        new Fighter(name: 'Lucario').save()
        new Fighter(name: 'Jigglypuff').save()
        new Fighter(name: 'Marth').save()
        new Fighter(name: 'Ike').save()
        new Fighter(name: 'Ness').save()
        new Fighter(name: 'Lucas').save()
        new Fighter(name: 'Mr. Game & Watch').save()
        new Fighter(name: 'Snake').save()
        new Fighter(name: 'Sonic').save()

        //STAGES--------------------------------------------------
        new Stage(name: 'Battlefield').save()
        new Stage(name: 'Final Destination').save()
        new Stage(name: 'Delfino Plaza').save()
        new Stage(name: 'Luigi\'s Mansion').save()
        new Stage(name: 'Mushroomy Kingdom').save()
        new Stage(name: 'Mario Circuit').save()
        new Stage(name: '75m').save()
        new Stage(name: 'Rumble Falls').save()
        new Stage(name: 'Pirate Ship').save()
        new Stage(name: 'Bridge of Eldin').save()
        new Stage(name:  'Norfair').save()
        new Stage(name: 'Frigate Orpheon').save()
        new Stage(name: 'Yoshi\'s Island').save()
        new Stage(name: 'Halberd').save()
        new Stage(name: 'Lylat Cruise').save()
        new Stage(name: 'Pokemon Stadium 2').save()
        new Stage(name: 'Spear Pillar').save()
        new Stage(name: 'Port Town Aero Dive').save()
        new Stage(name: 'Summit').save()
        new Stage(name: 'Flat Zone 2').save()
        new Stage(name: 'Castle Siege').save()
        new Stage(name: 'WarioWare, Inc.').save()
        new Stage(name: 'Distant Planet').save()
        new Stage(name: 'Skyworld').save()
        new Stage(name: 'Mario Bros.').save()
        new Stage(name: 'New Pork City').save()
        new Stage(name: 'Smashville').save()
        new Stage(name: 'Shadow Moses Island').save()
        new Stage(name: 'Green Hill Zone').save()
        new Stage(name: 'PictoChat').save()
        new Stage(name: 'Hanenbow').save()
        new Stage(name: 'Temple').save()
        new Stage(name: 'Yoshi\'s Island (Melee)').save()
        new Stage(name: 'Jungle Japes').save()
        new Stage(name: 'Onett').save()
        new Stage(name: 'Green Greens').save()
        new Stage(name: 'Rainbow Cruise').save()
        new Stage(name: 'Corneria').save()
        new Stage(name: 'Big Blue').save()
        new Stage(name: 'Brinstar').save()
        new Stage(name: 'Pokemon Stadium (Melee)').save()

        //BRACKETS-------------------------------------------------
        new Bracket(name: "Round Robin").save()
        new Bracket(name: "Quarter Finals").save()
        new Bracket(name: "Semi Finals").save()
        new Bracket(name: "Finals").save()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSomething() {//this is pretty messy...see if we can clean it up?
        def gfoi = new Tournament(name: "George Foreman Open I")

        //Players-------------------------------------------------------
        def wils = Player.findByFullName("Wilson Edens")
        def kros = Player.findByFullName("Adam Krosnick")
        def dan = Player.findByFullName("Daniel Shaver")
        def row = Player.findByFullName("Rowan Jones")

        //Matches-------------------------------------------------------
        def mAWi = new Match(tournament: gfoi,
                             stage: Stage.findByName("Final Destination"),
                             bracket: Bracket.findByName("Round Robin"))
        def mADi = new Match(tournament: gfoi,
                             stage: Stage.findByName("Final Destination"),
                             bracket: Bracket.findByName("Round Robin"))
        def mDWi = new Match(tournament: gfoi,
                             stage: Stage.findByName("Final Destination"),
                             bracket: Bracket.findByName("Round Robin"))

        //Matchships-----------------------------------------------------
        def msW1 = new Matchship(player: wils,
                                 character: Fighter.findByName("Falco"),
                                 match: mAWi,
                                 winner: true)
        def msW2 = new Matchship(player: wils,
                                 character: Fighter.findByName("Falco"),
                                 match: mDWi,
                                 winner: true)
        def msA1 = new Matchship(player: kros,
                                 character: Fighter.findByName("Toon Link"),
                                 match: mAWi,
                                 winner: false)
        def msA2 = new Matchship(player: kros,
                                 character: Fighter.findByName("Kirby"),
                                 match: mADi,
                                 winner: true)
        def msD1 = new Matchship(player: dan,
                                 character: Fighter.findByName("Ike"),
                                 match: mADi,
                                 winner: false)
        def msD2 = new Matchship(player: dan,
                                 character: Fighter.findByName("Ike"),
                                 match: mDWi,
                                 winner: false)

        //Setup----------------------------------------------------------------
        mADi.addToPlayers(msA2)
        mADi.addToPlayers(msD1)
        mDWi.addToPlayers(msW2)
        mDWi.addToPlayers(msD2)
        mAWi.addToPlayers(msA1)
        mAWi.addToPlayers(msW1)

        Player.findByFullName("Adam Krosnick").addToMatches(msA1)
        Player.findByFullName("Adam Krosnick").addToMatches(msA2)
        Player.findByFullName("Wilson Edens").addToMatches(msW1)
        Player.findByFullName("Wilson Edens").addToMatches(msW2)
        Player.findByFullName("Daniel Shaver").addToMatches(msD1)
        Player.findByFullName("Daniel Shaver").addToMatches(msD2)

        assertEquals(gfoi.findMatchByPlayer(wils, kros), mAWi)
        assertEquals(gfoi.findMatchByPlayer(wils, dan), mDWi)
        assertEquals(gfoi.findMatchByPlayer(dan, kros), mADi)
        assertEquals(gfoi.findMatchByPlayer(row, kros), null)

        //result:
        //groovy.lang.MissingMethodException:
        //No signature of method: gfo.Player.save() is applicable for argument types: () values: []
    }
}
